package cn.nuc.controller.sensorfire.before;

import cn.nuc.controller.login.LoginController;
import cn.nuc.pojo.sensorfire.Fire;
import cn.nuc.service.sensorfire.IFireService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class FireController2 {
    @Autowired
    private IFireService fireService;
@RequestMapping("fire")
    public String fire(Model model  , HttpServletRequest request){
    LoginController.url="fire";
    String pwdMsg = (String) request.getSession().getAttribute("pwdMsg");
    List<Fire> fireList = fireService.getAllFire();
        request.getSession().removeAttribute("pwdMsg");
    if(fireList != null){
            model.addAttribute("fireList" , fireList);
            model.addAttribute("pwdMsg" , pwdMsg);
            return "fire";
        }
        return "fail";
    }
    @RequestMapping("/local")
    public String localRefresh(Model model) {
        Object sensor = LoginController.session.getAttribute("sensor");
        System.out.println(sensor);
        model.addAttribute("sensor" , sensor);
        return "fire :: warn2";
    }
}
